package com.tuyue.police.dao;

import com.tuyue.police.pojo.Sector;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/3/13.
 * @Modified By:
 */
public interface ISectorDao extends JpaRepository<Sector,Long> {

    List<Sector> findAllBySectorDeviceId(Long deviceId);

    @Query(value = "SELECT s.* FROM\n" +
            "  sector s INNER JOIN device d ON (s.sector_device_id=d.device_id) INNER JOIN device_type t ON (t.device_type_id=d.device_type_id) INNER JOIN server se ON (se.server_id=d.device_server_id)\n" +
            "WHERE se.server_ip=?1 AND d.device_main_port=?2 AND s.sector_number=?3",nativeQuery = true)
    List<Sector> findAllByInfo(String serverIp,String deviceMainPort,String sectorNumber);

    @Query(value = "SELECT s.* FROM sector AS s INNER JOIN device d ON (s.sector_device_id=d.device_id) INNER JOIN enterprise AS e ON (d.device_enterprise_id=e.e_id) WHERE e.e_id=?1",nativeQuery = true)
    List<Sector> findAllByEnterprise(Long eid);

}
